package com.fstrat.backend.entities;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.codehaus.jackson.annotate.JsonIgnore;

@Entity
@Table(name = "Angebot")
@NamedQueries({@NamedQuery(name = "angebot.findeAlle", 
						   	query = "SELECT a FROM Angebot a"
						   			+ " ORDER BY a.titel, a.beschreibung")})
public class Angebot implements IEntity<Long>, Serializable {
	private static final long serialVersionUID = 6834304244118480249L;
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(unique = true, nullable = false, precision = 10)
	private Long id;
	@Column(nullable = false, length = 50)
	private String titel;
	@Column(nullable = false, length = 500)
	private String beschreibung;
	@Column
	private Double preis;
	@Column
	private Integer maxVerleihdauer;
	@Temporal(TemporalType.DATE)
	private Date ablaufdatum;
    @OneToOne
    @JoinColumn(name = "Adresse_Id", nullable = false)
	private Adresse adresse;
    @ManyToOne
    @JoinColumn(name = "User_ID", nullable = false)
	private User user;
    @JsonIgnore
	@OneToMany(mappedBy = "angebot", fetch=FetchType.LAZY)
	private List<Anfrage> anfrage;
    
	@Override
	public Long getId() {
		return id;
	}

	public String getTitel() {
		return titel;
	}

	public void setTitel(String titel) {
		this.titel = titel;
	}

	public String getBeschreibung() {
		return beschreibung;
	}

	public void setBeschreibung(String beschreibung) {
		this.beschreibung = beschreibung;
	}

	public Double getPreis() {
		return preis;
	}

	public void setPreis(Double preis) {
		this.preis = preis;
	}

	public Integer getMaxVerleihdauer() {
		return maxVerleihdauer;
	}

	public void setMaxVerleihdauer(Integer maxVerleihdauer) {
		this.maxVerleihdauer = maxVerleihdauer;
	}

	public Date getAblaufdatum() {
		return ablaufdatum;
	}

	public void setAblaufdatum(Date ablaufdatum) {
		this.ablaufdatum = ablaufdatum;
	}

	public Adresse getAdresse() {
		return adresse;
	}

	public void setAdresse(Adresse adresse) {
		this.adresse = adresse;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public List<Anfrage> getAnfrage() {
		return anfrage;
	}

	public void setAnfrage(List<Anfrage> anfrage) {
		this.anfrage = anfrage;
	}

}
